package com.adee.java;

import java.util.concurrent.atomic.AtomicInteger;

public class Test043_counter {
    static int counter = 0;

    static int max = 10;

    static AtomicInteger lock = new AtomicInteger(0); // 0-开锁，1-加锁

    public static void main(String[] args) {
        for (int i = 0; i < 50; i++) {

        }

    }

    public int increment() {
        while (lock.compareAndSet(0, 1)) {
            counter++;
            lock.set(0);
            return counter;
        }
        return 0;
    }
}
